<?php
/**
 * JS layout helper.
 *
 * @category Zend
 * @package Helper
 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc.
 * @version $Id$
 * @link http://framework.zend.com
 * @since Available since release 1.0
 * @license GPL v3
 */

class Zend_View_Helper_JavascriptHelper extends Zend_View_Helper_Abstract
{
    /**
     * Appends any JS file corresponding to module/action
     */
    function javascriptHelper() 
    {
        $layout = Zend_Layout::getMvcInstance();
        $view = $layout->getView();
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $file_uri = 'js/' . $request->getControllerName() . '/' . $request->getActionName() . '.js';
        $path = realpath(APPLICATION_PATH . '/../public/' . $file_uri);
        
        if (file_exists($path)) {
            echo $view->headScript()->appendFile('/' . $file_uri);
        }
    }
}